package com.acme.bankapp.domain.bank;

import com.acme.bankapp.exceptions.OverDraftLimitExceededException;

public class CheckingAccount extends AbstractAccount {

	private double overdraft;

	public CheckingAccount(double amount, double overdraft) {
		super(amount);
		if (overdraft < 0) {
			throw new IllegalArgumentException();
		}
		this.overdraft=overdraft;
	}
	
	@Override	
	public double maximumAmountToWithdraw() {
		return this.balance+this.overdraft; 
	}
	
	@Override
	public void withdraw(double amount) throws OverDraftLimitExceededException{
		if (maximumAmountToWithdraw() < amount) {
			throw new OverDraftLimitExceededException(" Over Draft Limit Exceeded. Amount=  "+amount+
					" maximumAmountToWithdraw =  "+maximumAmountToWithdraw());
		}
		if (this.balance > amount) {
			this.balance=this.balance-amount;
			System.out.println(" succsessful Your balance = "+this.balance+" your overdraft = "+this.overdraft);
			}
		else { 
			this.overdraft=maximumAmountToWithdraw()-amount;
			this.balance=0;
			System.out.println(" succsessful Your balance = "+this.balance+" your overdraft = "+this.overdraft);
		}
	}
}
